package com.bmmtwabp.employeedashbord.controller;

import com.bmmtwabp.employeedashbord.service.HeatService;
import com.bmmtwabp.employeedashbord.util.*;
import io.swagger.annotations.*;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 心跳-controller
 * @Param:
 * @return:
 * @Author: fenghouzhi
 * @Date: 9:42 AM 2018/10/22
 */
@Slf4j
@RestController
@Api(tags = "心跳接口")
public class HeartController extends BaseController {

  @Resource
  private HeatService heatService;

  /**
   * 心跳连接
   */
  @GetMapping("/heart")
  @ApiOperation(value = "心跳连接")
  ResponseVo heartInfo(@RequestParam("heartStr") String heartStr) {
    log.info("收到心跳消息:   " + heartStr);

    for (String item : CodeUtil.ZOOM_ARRAY) {
      String timeOutUserOpenId = heatService.getOpenIdForHeatTimeOut(item);
      if (timeOutUserOpenId != null) {
        log.info("{} 区域 {} 用户超时", item, timeOutUserOpenId);
      } else {
        log.info("{} 区域没有用户超时", item);
      }
    }

    return ResponseVo.ok();
  }

  @GetMapping("/sendMsg")
  @ApiOperation(value = "广播消息")
  ResponseVo senMsg(String openId, String msg) {
    log.info("msg info:   " + msg);
    WebSocketUtil.serverToClientMsg(openId, msg);
    return ResponseVo.ok("success", msg);
  }

}
